import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import { environment } from '@env/environment';
import { UtilService } from '@core/services/util.service';
import { Operator, Section } from '@core/config/dic.config';

@Component({
  selector: 'app-assess-forms-module',
  templateUrl: './assess-forms.component.html',
})
export class AssessFormsModuleComponent implements OnInit {
  @ViewChild('modalTmp', {static: false})modalTmp;
  @ViewChild('st', {static: false})st: TablePageComponent;
  downLoadUrl = environment.SERVER_URL + '/excel/work-assess/template/运营商申报设备模板.xls';
  config: SPage = {
    columns: [
      // {
      //   index: 'id',
      //   title: '选择',
      //   type: ColumnType.checkbox,
      // },
      {
        index: 'assessMonth',
        title: '统计月份',
        filter: {
          placeholder: '统计月份',
          type: 'date',
          mode: 'month'
        }
      },
      {
        index: 'sectionType',
        title: '标段',
        filter: {
          placeholder: '请选择标段',
          type: 'select',
          items: Section
        }
      },
      {
        index: 'sectionSupplier',
        title: '所属运营商',
        filter: {
          placeholder: '请选择运营商',
          type: 'select',
          items: Operator
        }
      },
      {
        index: 'sectionContractName',
        title: '合同名称',
        /*filter: {
          placeholder: '请输入合同名称',
          type: 'string'
        }*/
      },
      {
        index: 'installTotal',
        title: '安装套数',
       /* filter: {
          type: 'string'
        }*/
      },
      {
        index: 'declareTotal',
        title: '申报套数',
        /*filter: {
          type: 'string'
        }*/
      },
      {
        index: 'realPeopleNumber',
        title: '实名人数',
        /*filter: {
          type: 'string'
        }*/
      },
      {
        index: 'snapshotsPrice',
        title: '抓拍率',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'monthOnlinePrice',
        title: '月在线率',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'imagePrice',
        title: '图片质量',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'frontFacePrice',
        title: '正脸率',
        filter: {
          type: 'string'
        }
      },
    ],
    editBtn: [
      {title: '导出考核报表'},
      {title: '申报设备查看'},
    ],
    showCheckBox: true,
    reqUrl: this.api.accessReport.page.url,
  }
  deviceConfig: SPage = {
    columns: [
      {
        index: 'street',
        title: '街道',
      },
      {
        index: 'bm',
        title: '楼栋编码',
      },
      {
        index: 'houseName',
        title: '楼栋名',
      },
      {
        index: 'deviceId',
        title: '门禁机ID',
      },
      {
        index: 'deviceType',
        title: '门禁抓拍机型号',
      },
      {
        index: 'outDoorIPCType',
        title: '门外ipc型号',
      },
      {
        index: 'indoorIPCType',
        title: '门内ipc型号',
      },
    ],
    reqUrl: this.api.accessReport.page.url,
  }
  isVisible = false; // 弹窗
  isLoading = false;
  selectedFile: File;
  selectedData: any;
  operate(e): void {
    console.log(e);
    switch (e.title) {
      case '导出考核报表':
        this.export(e.data);
        break;
      case '申报设备查看':
        this.util.export(e.data.assessUploadPath);
        break;
    }
  }
  _console(e){
    console.log(e);
    this.selectedData = e;
  }
  selectFile(file: FileList): void{
    if (file && file.length > 0) {
      this.selectedFile = file[0];
    }
  }
  export(data): void {
    this.http.request<any>(this.api.accessReport.exportExcel.method, this.api.accessReport.exportExcel.url, {body: {assessUploadPath: data.assessUploadPath}}).subscribe(
      res => {
        if (res.status === '200') {
          this.util.export(res.data);
        }
      }
    )
  }
  handleOk(): void {
    this.isLoading = true;
    const formData = new FormData();
    formData.append('file', this.selectedFile);
    this.http.post(this.api.accessReport.importExcel.url, formData).subscribe(res => {
      this.isLoading = false;
      if (res.status === '200') {
        this.msg.success('导入成功');
        this.isVisible = false;
        this.st.reload();
      }
    })

  }
  constructor(
    private modal: NzModalService,
    public msg: NzMessageService,
    private api: ApiService,
    private http: _HttpClient,
    private util: UtilService
  ) { }

  ngOnInit() {
  }
}
